"use strict";

var sys=require('sys');
var yaml=require('yaml');
var fs=require('fs');
var log=require('logging');
var eyes=require('eyes');

var object=require("./object");
var scope=require("./scope");
var util=require("./util");
var method=require("./method");
var channel=require("./channel");

var system=JSON.parse(fs.readFileSync('system.json').toString());

var args = process.argv.splice(2);
var filename=args[0];

var test=JSON.parse(fs.readFileSync(filename).toString());
system.test=test;

var t=scope.treeToScope(system);

var x;
var unitTest;

for(x=0; x<test.active.length; x++)
{
  unitTest=scope.activate(t, ['test', test.active[x]], {});
  log('unitTest:', test.active[x]);
  log('unitTest:', unitTest.params);

  try
  {
    method.callMethod(unitTest, t, []);
  }
  catch(error)
  {
    process.stdout.on('drain', function() {
      sys.puts(error.stack);
    });
  }
}

//var stdOutFlush = process.stdout.flush();
//var stdErrFlush = process.stderr.flush();
//if(!stdOutFlush || !stdErrFlush)
//{

//  process.stderr.on('drain', function() {});
//}
